package com.mtsmda.webServices.rpcStyle.attach.client;

import java.awt.Image;
import java.io.File;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.jws.soap.SOAPBinding;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;

import com.mtsmda.webServices.rpcStyle.attach.WServiceRPCAttachI;

public class WServiceRPCAttachClient {

	public static void main(String[] args) throws Exception {
		URL wsdlUrl = new URL("http://localhost:9999/webseriveRPC/attach?wsdl");

		QName qName = new QName(
				"http://attach.rpcStyle.webServices.mtsmda.com/",
				"WServiceRPCAttachImplService");

		Service service = Service.create(wsdlUrl, qName);

		WServiceRPCAttachI port = service.getPort(WServiceRPCAttachI.class);
		Image image = port.downloadImage("koshak.jpg");

		// display the received image in a frame

		JFrame frame = new JFrame();

		frame.setSize(800, 800);

		JLabel label = new JLabel(new ImageIcon(image));

		frame.add(label);

		frame.setVisible(true);

		/********* Upload *************/

		Image imageToUpload = ImageIO.read(new File(
				"C:\\nikos7\\Pictures\\photo.jpg"));

		// enable MTOM

		BindingProvider bindingProvider = (BindingProvider) port;

		SOAPBinding sopadBinding = (SOAPBinding) bindingProvider.getBinding();

		// sopadBinding.setMTOMEnabled(true);

		String serverStatus = port.uploadImage(imageToUpload);

		System.out.println("Server returned Status : " + serverStatus);

	}

}